﻿<%@ WebHandler Language="C#" Class="LockedHandler" %>

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Chenxin.Lib.Utility;

public class LockedHandler : AjaxHandlerBase
{
    public LockedHandler()
    {
        htTypePermit.Add("add", Constants.Permit_HouseLockAdd);
        htTypePermit.Add("unlock", Constants.Permit_HouseLockUnLock);
    }

    override public void RequestProcess(HttpContext context)
    {
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        
        string strOp = context.Request["op"];

        string strResponse = "";
        switch (strOp.ToLower())
        {
            case "add"://封盘
                strResponse = AddLockInfo(context);
                break;
            case "unlock"://解封
                strResponse = updateLockInfo(context);
                break;
            case "getmodel"://初始化
                strResponse = init(context);
                break;
            case "validate": //验证
                strResponse = validate(context);
                break;
            case "getlist":
                strResponse = getLockedList(context);
                break;
            default:
                break;
        }

        context.Response.Write(strResponse);
    }

    //*******************************************
    //功能概要       ：封盘
    //参数説明       ：houseid 房源主键 requestStyle 请求方式 RequestChangeStyle状态变更 personId 所属人变更 txtSummary 请求说明
    //返回值説明     ：void
    //功能詳細       ：封盘
    //作成者         ：chen.yugong 
    //作成日         ：2010-03-02
    //修改者         ：
    //修改日         ：
    //*******************************************
    private string AddLockInfo(HttpContext context)
    {
        try
        {
            //转换成实体
            Chenxin.Lib.House.Entity.House_LockedInfo model = (Chenxin.Lib.House.Entity.House_LockedInfo)Chenxin.Lib.Utility.JsonHelp.Convert2Entity(context.Request["model"], typeof(Chenxin.Lib.House.Entity.House_LockedInfo));
            if (model.HouseId == null)
                return string.Format("{{success:'0',msg:'{0}',data:''}}", "房源标识丢失，请联系管理员！");
            //验证是否在House_BusinessSetting表设定范围之内
            Chenxin.Lib.House.Entity.House_BaseInfo houseInfo = Chenxin.Lib.House.DAL.House_BaseInfo.GetModel(model.HouseId);

            Chenxin.Lib.House.Entity.House_BusinessSetting bs = Chenxin.Lib.House.DAL.House_BusinessSetting.GetModel(houseInfo.OprDepartId);
            if (bs != null)
            {
                TimeSpan ts = model.LastTime - model.LockedTime;
                if (ts.Days < 0 || ts.Days > bs.LockHouseDay)
                {
                    return string.Format("{{success:'0',msg:'{0}',data:''}}", "封盘开始时间与结束时间之差超出规定范围！");
                }
            }

            //根据工号查询用户信息
            string workcode = context.Request["workcode"];
            Chenxin.Lib.Passport.Entity.Hr_UserInfo userInfo = Chenxin.Lib.Passport.DAL.Hr_UserInfo.GetEntityByCode(workcode);
            if (userInfo == null)
            {
                return string.Format("{{success:'0',msg:'{0}',data:''}}", "员工信息丢失，请联系管理员！");
            }

            Chenxin.Lib.House.Entity.House_BaseInfo house_BaseInfo = Chenxin.Lib.House.DAL.House_BaseInfo.GetModel(model.HouseId);
            //添加封盘信息
            model.HouseAddress = house_BaseInfo.Community + house_BaseInfo.BuildingName + house_BaseInfo.Room;
            model.CompanyId = userInfo.CompanyId;
            model.CompanyName = userInfo.CompanyName;
            model.AskerId = userInfo.UserId;
            model.CityId = userInfo.CityId;
            model.CityName = userInfo.CityName;
            model.Asker = userInfo.UserName;
            model.AskerDepart = userInfo.DepartName;
            model.AskerDepartId = userInfo.DepartId;

            model.LockedStatus = 1;
            model.Remarks = model.Remarks.Replace("\r", "\\r");
            model.OperatorId = CurrentUserInfo.UserId;
            model.Operator = CurrentUserInfo.UserName;
            model.DepartId = CurrentUserInfo.DepartId;
            model.Department = CurrentUserInfo.DepartName;
            model.UpdateTime = DateTime.Now;
            model.LockedId = Guid.NewGuid();
            model.InputTime = DateTime.Now;
            Chenxin.Lib.House.DAL.House_LockedInfo.Add(model);

            //更改房源状态
            if (house_BaseInfo.TraceNum == null)
                house_BaseInfo.TraceNum = 1;
            else
                house_BaseInfo.TraceNum = house_BaseInfo.TraceNum + 1;
            house_BaseInfo.Status = 30;
            house_BaseInfo.UpdateTime = DateTime.Now;
            house_BaseInfo.ServiceTime = DateTime.Now;
            Chenxin.Lib.House.DAL.House_BaseInfo.Update(house_BaseInfo);

            //清除缓存
            string strCachKey = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_HOUSEINFO, house_BaseInfo.HouseId);
            Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.GLOBAL);
            cs.Delete(strCachKey);
    
            //添加用户操作日志 2010-5-11 王玮 Add
            AddLog("" + CurrentUserInfo.UserName + "添加了一个房源封盘:[" + model.HouseAddress + "]房源已添加封盘。",
                    OperationType.OperationTypeComboList()["OprType_HouseLockAdd"].ToString());

            return string.Format("{{success:'1',msg:'{0}',data:''}}", "封盘成功");
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'意外错误：{0}',data:''}}", ex.Message);
        }
    }

    //*******************************************
    //功能概要       ：解封
    //参数説明       ：houseid 房源主键 
    //返回值説明     ：void
    //功能詳細       ：解封
    //作成者         ：chen.yugong 
    //作成日         ：2010-03-15
    //修改者         ：
    //修改日         ：
    //*******************************************
    private string updateLockInfo(HttpContext context)
    {
        try
        {    //转换成实体
            string modelid = context.Request["modelid"];
            if (string.IsNullOrEmpty(modelid))
                return string.Format("{{success:'0',msg:'{0}',data:''}}", "封盘标识丢失，请联系管理员！");
            Chenxin.Lib.House.Entity.House_LockedInfo model = Chenxin.Lib.House.DAL.House_LockedInfo.GetModel(new Guid(modelid));
            if (model == null)
                return string.Format("{{success:'0',msg:'{0}',data:''}}", "封盘信息丢失，请联系管理员！");
            //更新
            model.LockedStatus = -1;
            model.UpdateTime = DateTime.Now;
            Chenxin.Lib.House.DAL.House_LockedInfo.Update(model);

            //更改房源状态
            Chenxin.Lib.House.Entity.House_BaseInfo house_BaseInfo = Chenxin.Lib.House.DAL.House_BaseInfo.GetModel(model.HouseId);
            if (house_BaseInfo.TraceNum == null)
                house_BaseInfo.TraceNum = 1;
            else
                house_BaseInfo.TraceNum = house_BaseInfo.TraceNum + 1;
            house_BaseInfo.Status = 10;
            house_BaseInfo.UpdateTime = DateTime.Now;
            Chenxin.Lib.House.DAL.House_BaseInfo.Update(house_BaseInfo);

            //清除缓存
            string strCachKey = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_HOUSEINFO, house_BaseInfo.HouseId);
            Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.GLOBAL);
            cs.Delete(strCachKey);

            //添加跟单记录
            Chenxin.Lib.House.Entity.House_TraceInfo house_TraceInfo = new Chenxin.Lib.House.Entity.House_TraceInfo();
            //跟单方式
            house_TraceInfo.TraceType = 0;
            //跟单内容	 
            house_TraceInfo.TraceContext = CurrentUserInfo.UserName + "解封了房源！";
            //房源Id	 
            house_TraceInfo.HouseId = model.HouseId;
            //房源编号	
            house_TraceInfo.HouseCode = house_BaseInfo.HouseCode;
            //房源地址	 
            house_TraceInfo.HouseAddress = house_BaseInfo.Community + house_BaseInfo.BuildingName + house_BaseInfo.Room;
            house_TraceInfo.status = 0;
            house_TraceInfo.OprDepart = house_BaseInfo.OprDepart;
            house_TraceInfo.OprDepartId = house_BaseInfo.OprDepartId;
            house_TraceInfo.OprPerson = house_BaseInfo.OprPerson;
            house_TraceInfo.OprPersonId = house_BaseInfo.OprPersonId;
            AddTrace(house_TraceInfo);

            //添加用户操作日志 2010-5-11 王玮 Add
            AddLog("" + CurrentUserInfo.UserName + "解除了一个房源封盘:[" + model.HouseAddress + "]房源已解除封盘。",
                    OperationType.OperationTypeComboList()["OprType_HouseLockUnLock"].ToString());

            return string.Format("{{success:'1',msg:'{0}',data:''}}", "解封成功");
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'意外错误：{0}',data:''}}", ex.Message);
        }
    }
    //*******************************************
    //功能概要       ：初始化
    //参数説明       ：houseid 房源主键 
    //返回值説明     ：void
    //功能詳細       ：初始化
    //作成者         ：chen.yugong 
    //作成日         ：2010-03-02
    //修改者         ：
    //修改日         ：
    //*******************************************
    private string init(HttpContext context)
    {
        try
        {
            string houseId = context.Request["modelid"];
            if (houseId == null)
                return string.Format("{{success:'0',msg:'{0}',data:''}}", "房源标识丢失，请联系管理员！");
            string strWhere = string.Format("HouseId = '{0}' and LockedStatus = '{1}'", houseId, 1);
            System.Collections.Generic.List<Chenxin.Lib.House.Entity.House_LockedInfo> list = Chenxin.Lib.House.DAL.House_LockedInfo.GetListArray(strWhere);
            if (list.Count == 1)
            {
                Chenxin.Lib.House.Entity.House_LockedInfo modelInfo = list[0];
                return string.Format("{{success:'1',msg:'成功',data:{{{0}}}}}", Chenxin.Lib.Utility.JsonHelp.Convert2Json(modelInfo));
            }
            else
            {
                return string.Format("{{success:'0',msg:'{0}',data:''}}", "封盘记录不存在，或数据错误！");
            }
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'意外错误：{0}',data:''}}", ex.Message);
        }
    }


    //*******************************************
    //功能概要       ：验证工号
    //参数説明       ：personId 工号
    //返回值説明     ：void
    //功能詳細       ：验证工号
    //作成者         ：chen.yugong 
    //作成日         ：2010-03-02
    //修改者         ：
    //修改日         ：
    //*******************************************
    private string validate(HttpContext context)
    {
        try
        {
            string personId = context.Request["f_workcode"];
            Chenxin.Lib.Passport.Entity.Hr_UserInfo userInfo = Chenxin.Lib.Passport.DAL.Hr_UserInfo.GetEntityByCode(personId);
            if (userInfo != null)
            {
                return string.Format("{{success:'1',msg:'成功',data:{{model:{0}}}}}", Chenxin.Lib.Utility.JsonHelp.Convert2Json(userInfo));
            }
            else
            {
                return string.Format("{{success:'0',msg:'{0}',data:''}}", "用户不存在！");
            }
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'意外错误：{0}',data:''}}", ex.Message);
        }
    }
    private string getLockedList(HttpContext context)
    {

        try
        {
            int iPageIndex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;//页码
            int iPageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 30 : int.Parse(context.Request["pagesize"]);//页记录数

            string fieldlist = "LockedId,flg,HouseId,HouseCode,HouseAddress,LockedStatus,LockedTime,Asker,AskerDepart,Operator,Remarks,LastTime";
            string fieldtablelist = "A.LockedId,A.LockedStatus as flg,A.HouseId,A.HouseCode,A.HouseAddress,case A.LockedStatus when 1 then '封盘' when -1 then '解封' end as LockedStatus ,A.LockedTime,A.Asker,A.AskerDepart,A.Operator,A.Remarks,A.LastTime";
            string orderfield = "A.LockedStatus,A.InputTime desc";

            if (!string.IsNullOrEmpty(context.Request["sort"]))
                orderfield = context.Request["sort"];
            Guid city = (string.IsNullOrEmpty(context.Request["cityid"])) ? Guid.Empty : new Guid(context.Request["cityid"]);
            Guid company = (string.IsNullOrEmpty(context.Request["companyid"])) ? Guid.Empty : new Guid(context.Request["companyid"]);
            Guid businessdistrict = (string.IsNullOrEmpty(context.Request["areaid"])) ? Guid.Empty : new Guid(context.Request["areaid"]);
            Guid departs = (string.IsNullOrEmpty(context.Request["departid"])) ? Guid.Empty : new Guid(context.Request["departid"]);
            Guid employee = (string.IsNullOrEmpty(context.Request["userid"])) ? Guid.Empty : new Guid(context.Request["userid"]);

            //判断权限范围/////////////////////////////////////////////
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (employee != Guid.Empty)
                sb.AppendFormat(" AND (A.AskerId = '{0}' OR A.OperatorId = '{1}' ) ", employee, employee);
            else if (departs != Guid.Empty)
                sb.AppendFormat(" AND (A.AskerDepartId = '{0}' OR A.DepartId = '{1}' )", departs, departs);
            else if (businessdistrict != Guid.Empty)
            {
                Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo item = null;
                string strCachkey = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_DEPARTMENT, businessdistrict);
                Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.GLOBAL);
                item = cs.GetObject<Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo>(strCachkey);
                if (!cs.Hit)
                {
                    item = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetModel(businessdistrict);
                    if (item != null) cs.Set(strCachkey, item, DateTime.Now.AddDays(1));
                }

                if (item == null) return string.Format("{{success:'0',msg:'{0}',data:''}}", "获取商圈或分类数据丢失");

                sb.AppendFormat(" AND ((A.AskerDepartId in (select departId from v_Hr_DepartmentInfo where DepartSrc like '{0}%')) OR (A.DepartId in (select departId from v_Hr_DepartmentInfo where DepartSrc like '{1}%')))", item.DepartSrc, item.DepartSrc);
            }
            else if (company != Guid.Empty)
                sb.AppendFormat(" AND ((A.AskerDepartId in (Select DepartId from v_Hr_DepartmentInfo where CompanyId = '{0}')) OR (A.DepartId in (Select DepartId from v_Hr_DepartmentInfo where CompanyId = '{1}')))", company, company);
            else if (city != Guid.Empty)
                sb.AppendFormat(" AND ((A.AskerDepartId in (Select DepartId from v_Hr_DepartmentInfo where CityId = '{0}')) OR (A.DepartId in (Select DepartId from v_Hr_DepartmentInfo where CityId = '{1}')))", city, city);
            else
                sb.AppendFormat(" AND ((A.AskerDepartId in (Select DepartId from v_Hr_DepartmentInfo where CompanyId = '{0}')) OR (A.DepartId in (Select DepartId from v_Hr_DepartmentInfo where CompanyId = '{1}')))", CurrentUserInfo.CompanyId, CurrentUserInfo.CompanyId);

            System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
            //查看所有封盘
            if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewAllLockedHouse))
            {
                sb1.Append(" (1=1) ");
            }
            //查看城市封盘
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewCityLockedHouse))
            {
                sb1.Append("EXISTS(");
                sb1.Append("Select 1 from v_Hr_User_BaseInfo M ");
                sb1.AppendFormat("WHERE (A.AskerId = M.Userid OR A.OperatorId = M.Userid) AND  M.CityId= '{0}' ", CurrentUserInfo.CityId);
                sb1.Append(")");
            }
            //查看公司封盘
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewCompanyLockedHouse))
            {
                sb1.Append("EXISTS(");
                sb1.Append("Select 1 from v_Hr_User_BaseInfo M ");
                sb1.AppendFormat("WHERE (A.AskerId = M.Userid OR A.OperatorId = M.Userid) AND  M.CompanyId= '{0}' ", CurrentUserInfo.CompanyId);
                sb1.Append(")");
            }
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_ViewDepartLockedHouse))
            {
                sb1.Append("EXISTS(");
                sb1.Append("Select 1 from v_Struct_UserDepartRelation M ");
                sb1.AppendFormat("WHERE (A.AskerDepartId = M.Departid OR A.DepartId = M.Departid) AND  M.Userid= '{0}' AND M.ViewLockHouse =1 ", CurrentUserInfo.UserId);
                sb1.Append(")");
            }
            else
            {
                sb1.AppendFormat(" (A.AskerId='{0}' OR A.OperatorId ='{1}' )", CurrentUserInfo.UserId, CurrentUserInfo.UserId);
            }

            if (!String.IsNullOrEmpty(sb.ToString()))
                sb1.Append(sb.ToString());

            string stime = context.Request.QueryString["stime"];
            string etime = context.Request.QueryString["etime"];
            string keyword = context.Request.QueryString["keyword"];
            string status = context.Request.QueryString["LockedStatus"];

            if (!String.IsNullOrEmpty(stime))
            {
                sb1.Append(string.Format(" AND convert(varchar(10),(convert(datetime,A.LockedTime,120)),120)  >= '{0}'", (stime)));
            }
            if (!String.IsNullOrEmpty(etime))
            {
                sb1.Append(string.Format(" AND convert(varchar(10),(convert(datetime,A.LastTime,120)),120)  <= '{0}'", (etime)));
            }
            if (!String.IsNullOrEmpty(keyword))
            {
                sb1.AppendFormat(" And (B.DetailAddress Like '%{0}%' Or A.HouseCode Like '%{0}%' Or (B.Community+BuildingName+Room) Like '%{0}%') ", keyword);
            }
            if (!String.IsNullOrEmpty(status))
            {
                sb1.AppendFormat(" And A.LockedStatus={0}", status);
            }
            //判断权限范围结束////////////////////////////////////////////

            System.Data.DataSet list = null;
            list = Chenxin.Lib.House.DAL.House_MarkedInfo.GetList(iPageIndex, iPageSize, orderfield, "House_LockedInfo A left join House_BaseInfo B on A.HouseId = B.HouseId ", sb1.ToString(), fieldlist, fieldtablelist, true);
            int count = (int)list.Tables[1].Rows[0][0];
            string strHtml = "";
            if (!GetKeyListHtml(list, out strHtml))
            {
                return string.Format("{{success:'0',msg:'{0}',data:''}}", "生成HTML错误:" + strHtml);
            }
            list.Dispose();
            list = null;
             System.Text.StringBuilder head = new System.Text.StringBuilder();
            head.Append("{");
            head.AppendFormat("icon:{{width:{0},head:'{1}',inField:false}},", 50,"操作");
            head.AppendFormat("HouseCode:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 180, "房源编号","A.HouseCode");
            head.AppendFormat("HouseAddress:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 120, "房源地址","A.HouseAddress");
            head.AppendFormat("LockedStatus:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 50, "状态", "A.LockedStatus");
            head.AppendFormat("LockedTime:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 90, "封盘时间","A.LockedTime");
            head.AppendFormat("Asker:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 90, "请求人","A.Asker");
            head.AppendFormat("AskerDepart:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 90, "所属部门","A.AskerDepart");
            head.AppendFormat("Operator:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 90, "操作者", "SalePrice_T,RentPrice","A.Operator");
            head.AppendFormat("LockedTime_1:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}},", 90, "封盘开始", "A.LockedTime");
            head.AppendFormat("LastTime:{{width:{0},head:'{1}',sortable:true,sortField:'{2}'}}", 90, "封盘结束", "A.LastTime");
            

            return string.Format("{{success:'1',msg:'{0}',data:{{count:'{1}',html:'{2}'}}}}", "成功", count, strHtml);
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}',data:''}}", "未知错误：" + ex.Message);
        }
    }

    /// <summary>
    /// 返回列表；
    /// 根据查询参数生成查询条件1,根据权限设定生成查询条件2；
    /// 返回Json数据：{count:'30',data:'abc'}
    /// </summary>
    /// <param name="context"></param>
    private bool GetKeyListHtml(System.Data.DataSet dslist, out string strHtml)
    {
        try
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            int i = 0;
            foreach (System.Data.DataRow row in dslist.Tables[0].Rows)
            {
                int status = 0;
                if (!string.IsNullOrEmpty(Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "flg", "")))
                {
                    status = Convert.ToInt32(Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "flg", ""));
                }
                string button = string.Empty;
                if (1 == status)
                {
                    button = string.Format("<a name=\"{0}\" href=\"javascript:void(0)\" class=\"a_locked_remove\">解封</a>", row["LockedId"]);
                }
                else
                {
                    button = string.Format("<a name=\"{0}\" href=\"javascript:void(0)\" class=\"a_locked_aleredyremove\">解封</a>", row["LockedId"]);
                }

                sb.AppendFormat("<dl id=\"{0}\" class=\"tr_houselist\">", row["HouseId"].ToString());
                sb.AppendFormat("<dd>{0}</dd>", button);
                string st = string.Format("<a name=\"{1}\" class=\"a_favor_house\" href=\"ShowDetailInfo.aspx?houseid={1}\" target=\"blank\">{0}</a>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "HouseCode", ""), row["HouseId"]);
                sb.AppendFormat("<dd>{0}</dd>", st);
                sb.AppendFormat("<dd>{0}</dd>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "HouseAddress", ""));
                sb.AppendFormat("<dd>{0}</dd>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "LockedStatus", ""));
                sb.AppendFormat("<dd>{0:yyyy-MM-dd}</dd>", Convert.ToDateTime(Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "LockedTime", "")));
                sb.AppendFormat("<dd>{0}</dd>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "Asker", ""));
                sb.AppendFormat("<dd>{0}</dd>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "AskerDepart", ""));
                sb.AppendFormat("<dd>{0}</dd>", Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "Operator", ""));
                sb.AppendFormat("<dd>{0:yyyy-MM-dd}</dd>", Convert.ToDateTime(Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "LockedTime", "")));
                sb.AppendFormat("<dd>{0:yyyy-MM-dd}</dd>", Convert.ToDateTime(Chenxin.Lib.Utility.DatasetHelper.GetValue(row, "LastTime", "")));
                sb.Append("</dl>");
            }
            strHtml = sb.ToString();
            return true;
        }
        catch (Exception ex)
        {
            strHtml = ex.Message;
            return false;
        }
    }
    //*******************************************
    //功能概要       ：响应字符串
    //参数説明       ：strMsg 消息 
    //返回值説明     ：void
    //功能詳細       ：权限检查
    //作成者         ：chen.yugong 
    //作成日         ：2010-05-20
    //修改者         ：
    //修改日         ：
    //*******************************************
    public override bool CustomerCheckPermint(HttpContext context, out string strMsg)
    {
        if (context.Request["op"] != null)
        {
            string op = context.Request["op"].ToLower();
            //封盘和解盘
            if ((op.Equals("checkpermit") && "add".Equals(context.Request["code"])) || ("unlock").Equals(op))
            {
                Chenxin.Lib.House.Entity.House_LockedInfo lockedInfo = null;
             
                if (op.Equals("checkpermit") && "add".Equals(context.Request["code"]))
                {
                    Chenxin.Lib.House.Entity.House_BaseInfo model = null;
                   try
                    {
                        model = (Chenxin.Lib.House.Entity.House_BaseInfo)Chenxin.Lib.Utility.JsonHelp.Convert2Entity(context.Request["model"], typeof(Chenxin.Lib.House.Entity.House_BaseInfo));
                    }
                    catch (Exception e)
                    {
                        strMsg = "{success:0,msg:'"+e.Message+"',data:''}";
                        return false;
                    }
                    //所有权限
                    if (CurrentUserInfo.ContainsPermit(Constants.Permit_LockedHouse_All))
                    {
                        strMsg = "{success:1,msg:'',data:{permit:true}}";
                        return true;
                    }
                    //城市级权限
                    else if (CurrentUserInfo.ContainsPermit(Constants.Permit_LockedHouse_City))
                    {
                        if (CurrentUserInfo.CityId.Equals(model.CityId))
                        {
                            strMsg = "{success:1,msg:'',data:{permit:true}}";
                            return true;
                        }
                        else
                        {
                            strMsg = "{success:1,msg:'操作失败，您无此权限，请联系管理员！',data:{permit:false}}";
                            return false;
                        }
                    }
                    //公司级权限
                    else if (CurrentUserInfo.ContainsPermit(Constants.Permit_LockedHouse_Company))
                    {
                        if (CurrentUserInfo.CompanyId.Equals(model.CompanyId))
                        {
                            strMsg = "{success:1,msg:'',data:{permit:true}}";
                            return true;
                        }
                        else
                        {
                            strMsg = "{success:1,msg:'操作失败，您无此权限，请联系管理员！',data:{permit:false}}";
                            return false;
                        }
                    }
                    //部门级权限
                    else if (CurrentUserInfo.ContainsPermit(Constants.Permit_LockedHouse_Department))
                    {
                        if (checkDepartPermit("add", model.OprDepartId))
                        {
                            strMsg = "{success:1,msg:'',data:{permit:true}}";
                            return true;
                        }
                        else
                        {
                            strMsg = "{success:1,msg:'操作失败，您无此权限，请联系管理员！',data:{permit:false}}";
                            return false;
                        }
                    }
                    else {
                        strMsg = "{success:1,msg:'操作失败，您无此权限，请联系管理员！',data:{permit:false}}";
                        return false;
                    }
                }
                if (("unlock").Equals(op))
                {
                    string id = context.Request["modelid"];
                    if (string.IsNullOrEmpty(id))
                    {
                        strMsg = "{success:0,msg:'获取封盘数据失败！',data:''}";
                        return false;
                    }
                    lockedInfo = Chenxin.Lib.House.DAL.House_LockedInfo.GetModel(new Guid(id));
                    if (lockedInfo == null)
                    {
                        strMsg = "{success:0,msg:'获取封盘数据失败！',data:''}";
                        return false;
                    }
                    //所有权限
                    if (CurrentUserInfo.ContainsPermit(Constants.Permit_UnLockedHouse_All))
                    {
                        strMsg = "{success:1,msg:'',data:{permit:true}}";
                        return true;
                    }
                    //城市级权限
                    else if (CurrentUserInfo.ContainsPermit(Constants.Permit_UnLockedHouse_City))
                    {
                        strMsg = "{success:1,msg:'',data:{permit:true}}";
                        return true;
                    }
                    //公司级权限
                    else if (CurrentUserInfo.ContainsPermit(Constants.Permit_UnLockedHouse_Company))
                    {
                        strMsg = "{success:1,msg:'',data:{permit:true}}";
                        return true;
                    }
                    //部门级权限
                    else if (CurrentUserInfo.ContainsPermit(Constants.Permit_UnLockedHouse_Department))
                    {
                        //操作人和请求封盘人都可解        
                        if (checkDepartPermit("unlock", lockedInfo.DepartId) || checkDepartPermit("unlock", lockedInfo.AskerDepartId))
                        {
                            strMsg = "{success:1,msg:'',data:{permit:true}}";
                            return true;
                        }
                        else
                        {
                            strMsg = "{success:1,msg:'操作失败，您无此权限，请联系管理员！',data:{permit:false}}";
                            return false;
                        }
                    }
                    else {
                        strMsg = "{success:1,msg:'操作失败，您无此权限，请联系管理员！',data:{permit:false}}";
                        return false;
                    }
                }              
            }
        }
        strMsg = "{success:1,msg:'',data:{permit:true}}";
        return true;
    }
    
    //*******************************************
    //功能概要       ：部门内有无封盘解盘权限
    //参数説明       ：context 上下文
    //返回值説明     ：bool
    //功能詳細       ：部门内有无封盘解盘权限
    //作成者         ：chen.yugong 
    //作成日         ：2010-05-19
    //修改者         ：
    //修改日         ：
    //*******************************************
    public bool checkDepartPermit(string op,Guid departId)
    {
        //检查有无权限
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.AppendFormat(" (Departid = '{0}' AND  Userid= '{1}') ", departId, CurrentUserInfo.UserId);
        System.Collections.Generic.List<Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation> list = Chenxin.Lib.Hr.DAL.Struct_UserDepartRelation.GetListArray(sb.ToString());
        if (list!=null && list.Count > 0)
        {
            Chenxin.Lib.Hr.Entity.Struct_UserDepartRelation struct_UserDepartRelation = list[0];
            if("add".Equals(op)){
                return struct_UserDepartRelation.CanLockHouse;
            }
            
            if ("unlock".Equals(op)) {
                return struct_UserDepartRelation.CancelLockHouse;
            }
        }
        return false;
    }

}